/**
 * Created by fuguang on 2017/6/15.
 */

(function() {
    $(function() {
        $(document).on("click touchend", ".gridly .brick", function(event) {
            var $this, size;
            event.preventDefault();
            event.stopPropagation();
            $this = $(this);
            $this.toggleClass('small');
            $this.toggleClass('large');
            if ($this.hasClass('small')) {
                width = 180;
                height = 40;
            }
            if ($this.hasClass('large')) {
                width = 220;
                height = 40;
            }
            $this.data('width', width);
            $this.data('height', height);
            return $('.gridly').gridly('layout');
        });
        $(document).on("click", ".gridly .delete", function(event) {
            var $this;
            event.preventDefault();
            event.stopPropagation();
            $this = $(this);
            $this.closest('.brick').remove();
            return $('.gridly').gridly('layout');
        });
        $(document).on("click", ".add", function(event) {
            var txt = window.getSelection?window.getSelection():document.selection.createRange().text;
            var brick = "<div class='brick small'><div class='delete'>&times;</div><div class='keyword'>"+txt+"</div></div>";

            txt = txt.toString();
            if( !txt.length || txt.length <= 0 ){
                alert("Keyword can not be null !");
                return;
            }

            event.preventDefault();
            event.stopPropagation();
            $('.gridly').append(brick);
            return $('.gridly').gridly();
        });
        return $('.gridly').gridly();
    });

}).call(this);